<template>
	<view class="container">
		<!-- 自定义导航栏 -->
		<view class="custom-nav">
			<view class="nav-content">
				<view class="back" @click="handleBack">
					<text class="iconfont icon-back"></text>
				</view>
				<text class="title">设置</text>
			</view>
		</view>

		<!-- 设置列表 -->
		<view class="settings-list">
			<!-- 账号设置 -->
			<view class="settings-group">
				<view class="group-title">账号设置</view>
				<view class="settings-item" @click="goEdit">
					<view class="left">
						<text class="iconfont icon-register"></text>
						<text class="title">编辑资料</text>
					</view>
					<text class="iconfont icon-arrow-right"></text>
				</view>
				<view class="settings-item">
					<view class="left">
						<text class="iconfont icon-xinxi"></text>
						<text class="title">消息通知</text>
					</view>
					<switch :checked="notificationEnabled" @change="handleNotificationChange" color="#007AFF" />
				</view>
			</view>

			<!-- 通用设置 -->
			<view class="settings-group">
				<view class="group-title">通用设置</view>

				<view class="settings-item" @click="goAbout">
					<view class="left">
						<text class="iconfont icon-about"></text>
						<text class="title">关于我们</text>
					</view>
					<text class="iconfont icon-arrow-right"></text>
				</view>

				<!-- 版本更新 -->
				<view class="settings-item" @click="goToVersionUpdate">
					<view class="left">
						<text class="iconfont icon-cloud_computing_"></text>
						<text class="title">版本更新</text>
					</view>
					<text class="iconfont icon-arrow-right"></text>
				</view>
			</view>
		</view>

		<!-- 退出登录 -->
		<view class="logout" @click="handleLogout">
			<text class="iconfont icon-logout"></text>
			<text>退出登录</text>
		</view>

		<!-- 退出登录弹窗 -->
		<view class="modal" v-if="showLogoutModal" @click="closeModal" :class="{ show: showLogoutModal }">
			<view class="modal-backdrop"></view>
			<view class="modal-content" @click.stop :class="{ 'modal-slide-in': showLogoutModal }">
				<image src="/static/delault/logout-tip.png" mode="aspectFit" class="tip-image"></image>
				<view class="modal-header">
					<text class="title">确定要退出吗？</text>
				</view>
				<view class="modal-body">
					<text>退出后将无法接收到最新活动消息哦~</text>
				</view>
				<view class="modal-footer">
					<button class="btn cancel" @click="closeModal" hover-class="btn-hover">再想想</button>
					<button class="btn confirm" @click="confirmLogout" hover-class="btn-hover">确定退出</button>
				</view>

			</view>
		</view>


	</view>
</template>

<script setup>
import { ref } from 'vue'

const notificationEnabled = ref(true)

const handleNotificationChange = (e) => {
	notificationEnabled.value = e.detail.value
}

const goEdit = () => {
	uni.navigateTo({
		url: '/pages/user/edit'
	})
}

// 添加弹窗控制
const showLogoutModal = ref(false)

// 修改退出登录方法
const handleLogout = () => {
	showLogoutModal.value = true
}

// 关闭弹窗
const closeModal = () => {
	showLogoutModal.value = false
}

// 确认退出
const confirmLogout = () => {
	// uni.removeStorageSync('userInfo')
	// uni.removeStorageSync('user_id')
	// 删除全部本地数据
	uni.clearStorageSync()
	uni.showToast({
		title: '已退出登录',
		icon: 'success'
	})
	setTimeout(() => {
		closeModal()
		uni.switchTab({
			url: '/pages/user/profile'
		})
	}, 1500)
}

const handleBack = () => {
	// uni.navigateBack()
	uni.switchTab({
		url: '/pages/user/profile'
	})
}

const goAbout = () => {
	uni.navigateTo({
		url: '/pages/user/about'
	})
}

const goToVersionUpdate = () => {
	uni.navigateTo({
		url: '/pages/user/version-update'
	})
}
</script>

<style lang="scss" scoped>
.container {
	background-color: #f5f5f5;
	min-height: 100vh;

	.custom-nav {
		position: fixed;
		top: 0;
		left: 0;
		right: 0;
		z-index: 100;
		background-color: #fff;
		padding-top: var(--status-bar-height);
		box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.05);

		.nav-content {
			position: relative;
			height: 88rpx;
			display: flex;
			align-items: center;
			justify-content: center;
			padding: 0 30rpx;

			.back {
				position: absolute;
				left: 30rpx;
				top: 50%;
				transform: translateY(-50%);
				padding: 10rpx;
				z-index: 1;

				.iconfont {
					font-size: 40rpx;
					color: #333;
				}

				&:active {
					opacity: 0.7;
				}
			}

			.title {
				font-size: 36rpx;
				font-weight: bold;
				color: #333;
				position: relative;
				z-index: 0;
			}
		}
	}

	.settings-list {
		padding-top: calc(var(--status-bar-height) + 88rpx + 20rpx);
		background-color: #f5f5f5;

		.settings-group {
			margin-bottom: 20rpx;
			background: #fff;

			.group-title {
				padding: 20rpx 30rpx;
				font-size: 28rpx;
				color: #999;
			}

			.settings-item {
				display: flex;
				justify-content: space-between;
				align-items: center;
				padding: 30rpx;
				border-bottom: 1rpx solid #f5f5f5;

				.left {
					display: flex;
					align-items: center;

					.iconfont {
						font-size: 40rpx;
						margin-right: 20rpx;
						color: #666;
					}

					.title {
						font-size: 30rpx;
						color: #333;
					}
				}

				.value {
					font-size: 28rpx;
					color: #999;
				}

				.iconfont {
					color: #999;
					font-size: 32rpx;

					&.icon-arrow-right {
						color: #ccc;
					}
				}

				&:active {
					background-color: #f9f9f9;
				}
			}
		}
	}

	.logout {
		margin: 60rpx 30rpx;
		padding: 30rpx;
		background: #fff;
		text-align: center;
		font-size: 32rpx;
		color: #ff4d4f;
		border-radius: 12rpx;
		display: flex;
		align-items: center;
		justify-content: center;

		.iconfont {
			font-size: 36rpx;
			margin-right: 10rpx;
		}

		&:active {
			opacity: 0.7;
		}
	}
}

.modal {
	position: fixed;
	top: 0;
	left: 0;
	right: 0;
	bottom: 0;
	z-index: 999;
	display: flex;
	align-items: center;
	justify-content: center;
	opacity: 0;
	visibility: hidden;
	transition: all 0.3s ease-out;

	&.show {
		opacity: 1;
		visibility: visible;
	}

	.modal-backdrop {
		position: absolute;
		top: 0;
		left: 0;
		right: 0;
		bottom: 0;
		background-color: rgba(0, 0, 0, 0.2);
		backdrop-filter: blur(10rpx);
	}

	.modal-content {
		position: relative;
		background-color: #fff;
		border-radius: 30rpx;
		// overflow: hidden;
		transform: scale(0.8);
		opacity: 0;
		transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
		box-shadow: 0 20rpx 40rpx rgba(0, 0, 0, 0.1);

		&.modal-slide-in {
			transform: scale(1);
			opacity: 1;
		}

		.tip-image {
			position: absolute;
			left: 50%;
			transform: translateX(-50%);
			width: 200rpx;
			top: -300rpx;

			z-index: 1;
			pointer-events: none;
			object-fit: contain;
		}

		.modal-header {
			padding: 160rpx 30rpx 30rpx;
			text-align: center;

			.title {
				font-size: 36rpx;
				font-weight: bold;
				color: #333;
			}
		}

		.modal-body {
			padding: 20rpx 40rpx 60rpx;
			text-align: center;

			text {
				font-size: 28rpx;
				color: #666;
				line-height: 1.6;
			}
		}

		.modal-footer {
			display: flex;
			padding: 20rpx;
			gap: 20rpx;

			.btn {
				flex: 1;
				// height: 88rpx;
				line-height: 88rpx;
				text-align: center;
				font-size: 32rpx;
				border-radius: 44rpx;
				border: none;
				transition: all 0.2s ease;

				&::after {
					border: none;
				}

				&.cancel {
					background: #f5f5f5;
					color: #666;
				}

				&.confirm {
					background: #ff4d4f;
					color: #fff;
				}

				&.btn-hover {
					transform: scale(0.98);
					opacity: 0.9;
				}
			}
		}
	}
}
</style>